
import tkinter

from PIL import Image, ImageTk


class msgTkinterClass():
    def a001(self,isFail=False,msg=None):
        """
        :param isFail: 用于判断是否启动失败
        """
        # print(isFail)
        self.clock_time = 5
        self.root = tkinter.Tk()
        self.root.wm_attributes('-topmost', 1)
        # 设置窗体标题
        self.root.title('程序提示')
        self.root.iconbitmap("logo.ico")
        self.root.configure(bg='#FFFFFF')
        # # 设置窗口大小和位置
        width = 300
        height = 200
        # 找到电脑的长宽
        screenwidth = self.root.winfo_screenwidth()
        screenheight = self.root.winfo_screenheight()
        # 设置窗口大小和位置
        size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.root.geometry(size_geo)
        if isFail == True:
            # label = tkinter.Label(self.root, text=msg, bg='#FFFFFF', font=('微软雅黑', 10), foreground='#666666',width=width-10,wraplength=width)
            # label.pack(expand=True, fill=tkinter.BOTH)
            # # label.place()
            # text = tkinter.Text(self.root, undo=False, autoseparators=False)
            # text.pack()
            frame_1 = tkinter.Frame(self.root)
            frame_1.pack(fill=tkinter.BOTH, expand=tkinter.YES)  # 一个都不能少

            text =tkinter.Text(frame_1)
            text.pack(fill=tkinter.BOTH, expand=tkinter.YES)
            text.insert(tkinter.INSERT,msg)
        else:
            self.detime = tkinter.Label(self.root, text=60, bg='#5177c7', foreground='white',
                                        activebackground='#7492D2',
                                        font=('微软雅黑', 12), relief='raised')
            self.detime.place(x=width / 2 -30, y = 60)


        screen_width = self.root.winfo_screenwidth()
        screen_height = self.root.winfo_screenheight()

        window_size = '{width}x{height}+{screen_width}+{screen_height}'.format(width=width, height=height,
                                                                               screen_width=round(
                                                                                   (screen_width - width) / 2),
                                                                               screen_height=round(
                                                                                   (screen_height - height) / 2))
        self.root.geometry(window_size)  # 窗口大小
        if isFail == False:
            self.refresh_current_time()
        self.root.mainloop()
    def refresh_current_time(self):
        """刷新当前时间"""
        self.detime.config(text="启动中"+str(self.clock_time))
        self.clock_time -= 1
        self.detime.after(1000, self.refresh_current_time)
        if self.clock_time < 0:
            self.root.destroy()
        return


